setInterval(function () {
    var myDate = new Date;
    var year = myDate.getFullYear(); //获取当前年
    var mon = myDate.getMonth() + 1; //获取当前月
    var date = myDate.getDate(); //获取当前日
    var h = myDate.getHours(); //获取当前小时数(0-23)
    var m = myDate.getMinutes(); //获取当前分钟数(0-59)
    var s = myDate.getSeconds(); //获取当前秒
    var week = myDate.getDay();
    var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
    var time = year + "-" + mon + "-" + date + " " + weeks[week] + "   " + (h < 10 ? '0' : '') + h + ":" + (m < 10 ? '0' : '') + m + ":" + (s < 10 ? '0' : '') + s;
    $("#system-time").html(time);
}, 1000);

function transfer(previous, current, target, timeout, instantPass, callback) {
    previous.hide();
    current.show();
    $(".return-second").html(timeout);
    var returnInterval = setInterval(function () {
        timeout--;
        $(".return-second").html(timeout);
        if (timeout == 0) {
            clearInterval(returnInterval);
            previous.show();
            current.hide();
            callback(false);
            return;
        }
    }, 1000);
    if (instantPass == true) {
        $(document).on("click", ".check-pass", function (e) {
            e.preventDefault();
            current.hide();
            target.show();
            $(document).off("click", ".check-pass");
            $(document).off("click", ".back");
            clearInterval(returnInterval);
            callback(true);
            return;
        });
    }
    $(document).on("click", ".back", function (e) {
        e.preventDefault();
        current.hide();
        previous.show();
        $(document).off("click", ".check-pass");
        $(document).off("click", ".back");
        clearInterval(returnInterval);
        callback(false);
        return;
    });
}

var takeNumber = $(".take-number");
var idScan = $(".id-scan");
var systemPause = $(".system-pause");
var showNumber = $(".show-number");

    $('.btn-primary').click(function(){
        $.ajax({
            type: "GET",
            url: "/withdraw/common",
            dataType: "json",
            success: function(data){
                $('.current-number').text(data["number"]);
                $('.waiting-number').text(data["current"]);
            }
        });
    });

$('.btn-warning').click(function(){
    $.ajax({
        type: "GET",
        url: "/withdraw/vip",
        dataType: "json",
        success: function(data){
            $('.current-number').text(data["number"]);
            $('.waiting-number').text(data["current"]);
        }
    });
});
(function withdrawNumber() {
    $(document).on("click", ".take-number .buttons button", function (e) {




        e.preventDefault();
        var service_type = $(this).text();
        $("#service-stop").hide();
        $("#service-type").text(service_type);
        transfer(takeNumber, showNumber, takeNumber, 10, false, function (result) {
            if (!result) {
                $("#service-stop").show();
            }
        });
    })
})();

(function stopService() {
    $(document).on("click", "#service-stop", function (e) {
        $("#service-stop").hide();
        transfer(takeNumber, idScan, systemPause, 30, true, function (result) {
            if (!result) {
                $("#service-stop").show();
            }
        });
    });
})();

(function startService() {
    $(document).on("click", "#service-start", function (e) {
        transfer(systemPause, idScan, takeNumber, 30, true, function (result) {
            if (result) {
                $("#service-stop").show();
            }
        });
    });
})();